<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<? 

// --- JBL

	include "smart.lib.php"; 
	include "dict.lib.php";
	include "languages/".getUserLanguage().".php";
	
	$cMode = isset($_POST['m']) ? $_POST['m'] : $_GET['m'];

?>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <? echo commonMeta('Jagd W&ouml;rterbuch'); ?>
</head>

<?
	$cMode = isset($_POST['m']) ? $_POST['m'] : $_GET['m'];
	if (empty($cMode)) $cMode = 'none';

	switch ($cMode) {
		case 'none':
			showPage('alphabet');
			break;
	
		case 'list':
			showPage('list');
			break;
	
	default:
		break;
}

?>
	
	
</body>
</html>

<?


function showPage ($cKey) {

	echo '<body>';
	
	switch ($cKey) {
		case 'alphabet':
			echo '<div id="topbar">';
			echo '<div id="title">Jagd W&ouml;rterbuch</div>';
			echo '</div>';
			echo '<span class="graytitle">'.$appText['general']['list_selection'].'</span>';
			echo '<ul class="pageitem">';
			for ($i=0; $i<26; $i++) {
				echo '<li class="menu"><a href="'.myself().'?m=list&s='.chr($i+65).'">'; 
				echo '<span class="name">'.chr($i+65).' - '.chr($i+66).'</span><span class="arrow"></span></a>';
				echo '</li>';
				$i++;
			}
			echo '</ul>';
			break;
			
		case 'list':
			echo '<div id="topbar">';
			echo '<div id="leftnav"><a href="'.myself().'">Back</a></div>';
			echo '<div id="title">Jagd W&ouml;rterbuch</div>';
			echo '</div>';
			$cStart = isset($_POST['s']) ? $_POST['s'] : $_GET['s'];
			echo '<ul class="pageitem">';
			listWords('english', $cStart, 'list');
			echo '</ul>';
			break;
			
		default:
			break;
	}
	
	echo '<div id="footer">';
	echo 'Das Jagd W&ouml;rterbuch von <b>Jagd und Wild</b>';
	echo '</div>';
}


function listWords ($lang,$qchar1,$qmode) {
	$qchar2 = chr(ord($qchar1)+1);
	$db = new PDO("sqlite:dictionary.s3db");
	$table = getLang('german','M') . '_' . getLang($lang,'M');
	$sLang = getLang($lang,'S');
	$result = $db->query("SELECT * FROM ".$table." WHERE textde LIKE '".$qchar1."%' OR textde LIKE '".$qchar2."%' ORDER BY textde ASC");
	echo '<p><table>';
	foreach ($result as $data) {
		if ($qmode == 'edit') {
			$link = '<a href="?m=edit&l=german&w='.$data['textde'].'">';
			$link .= $data['textde'];
			$link .= '</a>';
		} 
		else {
			$link = $data['textde'];
		}
		echo '<tr><td><b>' . $link . '</b> ' . optShow('{}', $data['sexde']) . ' ' . optShow('[]', $data['ipade']) . '</td>';
		if ($qmode == 'edit') {
			$link = '<a href="?m=edit&l='.getLang($lang,'L').'&w='.$data['text'.$sLang].'">';
			$link .= $data['text'.$sLang];
			$link .= '</a>';
		} 
		else {
			$link = $data['text'.$sLang];
		}
		echo '<td><b>' . $link . '</b> ' . optShow('{}', $data['sex'.$sLang]) . ' ' . optShow('[]', $data['ipa'.$sLang]) . '</td>';
		if ($qmode == 'edit') {
			echo '<td><a href="?m=unlink&l='.getLang($lang,'L').'&w1='.$data['textde'].'&w2='.$data['text'.$sLang].'">unlink</a></td>';
		}
		echo '</tr>';
	}
	echo '</table></p>';
	$db = null;

}


function showAlphabet () {

	for ($i=0; $i<26; $i++) {
		echo '<li class="menu"><a href="'.myself().'?m=list&s='.chr($i+65).'">'; 
		echo '<span class="name">'.chr($i+65).' - '.chr($i+66).'</span><span class="arrow"></span></a>';
		echo '</li>';
		$i++;
	}

}

?>